#############################################################################
# Copyright (c) 2009 Dmitry Grushin <dgrushin@gmail.com>.
#
# This file is part of clupower (cluster power manager utility)
#
# Clupower is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Clupower is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Clupower.  If not, see <http://www.gnu.org/licenses/>.
#
# Contributors:
#    Dmitry Grushin <dgrushin@gmail.com> - initial API and implementation
#############################################################################

require 'settings'

class Utils
  def Utils.is_day_now
    now = Time.now.hour
    return now >= Settings.instance.get('DAY_START') && now < Settings.instance.get('DAY_END')
  end

  def Utils.human_time(time)
    d = time / 86400
    h = time % 86400 / 3600
    m = time % 86400 % 3600 / 60
    s = time % 86400 % 3600 % 60

    tstr = ""
    tstr += "#{d}D " if d > 0
    tstr += "#{h}H " if h > 0
    tstr += "#{m}M " if m > 0
    tstr += "#{s}S"  if s > 0 || (d == 0 && h == 0 && m == 0)
    return tstr
  end

  def Utils.get_lock_file
    Settings.instance.get('CP_RUN_DIR') + File::SEPARATOR + "clupower.lock"
  end
end